﻿
@{
    ViewData["Title"] = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>编辑</h2>

<form>
    <div class="form-group">
        <input type="hidden" id="articleid" name="articleid" value="@Model.ID" />
        <label for="articlename">标题:</label>
        <input type="text" class="form-control" id="articlename" name="articlename" value="@Model.Name" />
    </div>
    <div class="form-group">
        <label for="articlecontent">内容:</label>
        <textarea rows="15" cols="20" id="articlecontent" name="articlecontent" class="form-control">@Model.Contents</textarea>
    </div>
    <input type="button" onclick="btnEdit()" value="提交">
</form>

<script type="text/javascript">
	function btnEdit(){
        var articleid = $.trim($("#articleid").val());
		var articlename = $.trim($("#articlename").val());
		var articlecontent = $.trim($("#articlecontent").val());

        if(articlename=="")
        {
            alert("标题不能为空");
        }
        else if(articlecontent=="")
        {
            alert("内容不能为空");
        }
        else{
            var params={};
            params.articleid=articleid;
            params.articlename=articlename;
            params.articlecontent=articlecontent;

            $.ajax({
                url:'/Article/ArticleEdit',
                type:'post',
                data:params,
                dataType:'json',
                async:true,
                error:function(){
                    alert('编辑失败！');
                },
                success:function(data){
                    if(data.code=='success'){
                        alert('编辑成功');
                        window.location.reload();
                    }
                    else{
                        alert(data.msg);
                    }
                }
            });
        }
	}
</script>

